package com.tinno.chargelauncher.receiver;

import android.app.KeyguardManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;

import com.tinno.chargelauncher.charge.WiredChargingAnimation;
import com.tinno.chargelauncher.utils.BatteryUtils;

import org.w3c.dom.Text;

public class MultifunctionReceiver extends BroadcastReceiver {

	private static final String TAG = MultifunctionReceiver.class.getSimpleName();

	private KeyguardManager mKeyguardManager;

	@Override
	public void onReceive(Context context, Intent intent) {
		Log.d(TAG, "onReceive: MultifunctionReceiver");

		if (intent == null){
			return;
		}

		if (mKeyguardManager == null){
			mKeyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
		}
		
		String action = intent.getAction();
		Log.d(TAG, "onReceive: action: " + action);
		Log.d("wangX", "onReceive: ---> " + action);
		if (TextUtils.equals(Intent.ACTION_POWER_CONNECTED, action)){
			if (mKeyguardManager.isKeyguardLocked()){
				Log.d("wangX", "isLock ---> : " + (mKeyguardManager.isKeyguardLocked()));
				WiredChargingAnimation.makeWiredChargingAnimation(context.getApplicationContext(), null, BatteryUtils.getCurrentLevel(context.getApplicationContext()), false).show();
			}
		}else if (TextUtils.equals(Intent.ACTION_POWER_DISCONNECTED, action)){
			WiredChargingAnimation.makeWiredChargingAnimation(context.getApplicationContext(), null, BatteryUtils.getCurrentLevel(context.getApplicationContext()), false).hide();
		}
	}
}
